<?php

namespace app\store\service;

use think\facade\Db;

class LabelService
{
    /**
     * 新增
     */
    public static function saveGoodsCategory($data)
    {
        $rst = Db::name('offline_shop_label')
            ->insert(['name' => $data['name'], 'store_id'=>$data['store_id'],'sort' => $data['sort'], 'status' => $data['status'],
                 'create_time' => time()]);
        return $rst;
    }

    /**
     * 修改
     */
    public static function modify($data)
    {
        $rst = Db::name('offline_shop_label')
            ->where('id', $data['id'])
            ->where('store_id', session('store_id'))
            ->update(['name' => $data['name'], 'sort' => $data['sort'], 'status' => $data['status'],
                'update_time' => time()]);
        return $rst;
    }

    /**
     * 分类详情
     */
    public function findCategory($id)
    {
        $list = Db::name('offline_shop_label')
            ->where('id', $id)
            ->where('store_id', session('store_id'))->find();
        return $list;
    }

    /**
     * 标签列表
     */
    public function getCategoryList($keyword = '')
    {
        $list = Db::name('offline_shop_label')
        ->order('sort', 'desc')
        ->where('delete_time', 0)
        ->where('store_id', session('store_id'))->paginate(10)->each(function($item){
            $item['create_time'] = date('Y-m-d H:i:s',$item['create_time']);
            return $item;
        });
        return $list;
    }

    /**
     * 更新状态
     */
    public static function update($data)
    {
        $rst = Db::name('offline_shop_label')->where('store_id', session('store_id'))
            ->where('id', $data['id'])->update(['status' => $data['status']]);
        return $rst;
    }

    /**
     * 删除
     */
    public static function destroy($id) {
        $rst = Db::name('offline_shop_label')
        ->where('store_id', session('store_id'))->where('id', $id)
        ->update(['delete_time'=>time()]);
        return $rst;
    }
}
